import { createWebHistory, createRouter } from 'vue-router'
import home from '../vise/home/home.vue'
import login from '../vise/login.vue'
import xq from '../vise/home/xq.vue'
import Homelist from '../vise/home/homelist.vue'
import Xqq from '../vise/home/xqq.vue'

const routes = [
    { path: '/', redirect: '/home' },
    {
        path: '/home',
        component: home,
        children: [
            {
                path: 'xq',
                component: xq,
            },
            {
                path: 'homelist',
                component: Homelist,
            },
            { path: 'xqq', component: Xqq },
        ]
    },
    { path: '/login', component: login },
    
]

export const router = createRouter({
    history: createWebHistory(),
    routes,
})
router.beforeEach((to, from) => {
    if (to.fullPath !== '/login') {
        let token = localStorage.getItem('token')
        if (!token) {
            return {
                path: '/login'
            }
        }
    }
})